package com.ruoyi.web.controller.match;

import java.util.List;

import com.ruoyi.system.domain.match.BmMatchInfo;
import com.ruoyi.system.service.match.IBmMatchDetailService;
import com.ruoyi.system.service.match.IBmMatchInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 比赛信息Controller
 * 
 * @author xiangzhipeng
 * @date 2022-11-29
 */
@Controller
@RequestMapping("/match/match")
public class BmMatchInfoController extends BaseController
{
    private String prefix = "match/match";

    @Autowired
    private IBmMatchInfoService bmMatchInfoService;

    @RequiresPermissions("match:match:view")
    @GetMapping()
    public String match()
    {
        return prefix + "/match";
    }

    /**
     * 查询比赛信息列表
     */
    @RequiresPermissions("match:match:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BmMatchInfo bmMatchInfo)
    {
        startPage();
        List<BmMatchInfo> list = bmMatchInfoService.selectBmMatchInfoList(bmMatchInfo);
        return getDataTable(list);
    }

    /**
     * 导出比赛信息列表
     */
    @RequiresPermissions("match:match:export")
    @Log(title = "比赛信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BmMatchInfo bmMatchInfo)
    {
        List<BmMatchInfo> list = bmMatchInfoService.selectBmMatchInfoList(bmMatchInfo);
        ExcelUtil<BmMatchInfo> util = new ExcelUtil<BmMatchInfo>(BmMatchInfo.class);
        return util.exportExcel(list, "比赛信息数据");
    }

    /**
     * 新增比赛信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存比赛信息
     */
    @RequiresPermissions("match:match:add")
    @Log(title = "比赛信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BmMatchInfo bmMatchInfo)
    {
        bmMatchInfo.setCreateBy(getLoginName());
        return toAjax(bmMatchInfoService.insertBmMatchInfo(bmMatchInfo));
    }

    /**
     * 修改比赛信息
     */
    @RequiresPermissions("match:match:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        BmMatchInfo bmMatchInfo = bmMatchInfoService.selectBmMatchInfoById(id);
        mmap.put("bmMatchInfo", bmMatchInfo);
        return prefix + "/edit";
    }
    @Autowired
    private IBmMatchDetailService bmMatchDetailService;
    /**
     * 查询字典详细
     */
    @RequiresPermissions("match:ItemDetail:list")
    @GetMapping("/detail/{matchId}")
    public String itemDetail(@PathVariable("matchId") Long matchId, ModelMap mmap)
    {
        mmap.put("matchItemList", bmMatchDetailService.selectBmMatchDetailByMatchId(matchId));
        return "match/detail/detail";
    }

    /**
     * 修改保存比赛信息
     */
    @RequiresPermissions("match:match:edit")
    @Log(title = "比赛信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BmMatchInfo bmMatchInfo)
    {
        return toAjax(bmMatchInfoService.updateBmMatchInfo(bmMatchInfo));
    }

    /**
     * 删除比赛信息
     */
    @RequiresPermissions("match:match:remove")
    @Log(title = "比赛信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bmMatchInfoService.deleteBmMatchInfoByIds(ids));
    }
}
